<?php
class Get_DB_Data_model extends CI_Model
{
	//get all software data
	public function get_software_all()
	{
		$query = $this->db->get('software');
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row)
			{
				$data[] = $row;
			}
			return $data;
		}
	}
	
	//get hardware data
	public function get_hardware_all()
	{
		$query = $this->db->get('hardware');
		if($query->num_rows > 0)
		{
			foreach ($query->result() as $row)
			{
				$data[] = $row;
			}
		}
		return $data;
	}
	
	//get all lab room
	public function get_lab_room_data()
	{
		$array = array('roomtype'=>0);
		$query = $this->db->get_where('room', $array);
		if($query->num_rows > 0)
		{
			foreach ($query->result() as $row)
			{
				$data[] = $row;
			}
			return $data;
		}
	}
	
	//get all meeting room
	public function get_meeting_room_data()
	{
		$array = array('roomtype'=>1);
		$query = $this->db->get_where('room', $array);
		if($query->num_rows > 0)
		{
			foreach ($query->result() as $row)
			{
				$data[] = $row;
			}
			return $data;
		}
	}
	
	//get reservation data from key
	public function get_reservation_data_from_key($key)
	{
		$array = array('reskey' => $key);
		$query = $this->db->get_where('reservation', $array);
		
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row) 
			{
				$data[] = $row;
			}
			return $data;
		}
		else{
			return false;
		}
		
	}
	//get reservation data from key
	
	//get name from id
	public function get_name_from_id($id)
	{
		$array = array('memid' => $id);
		$query = $this->db->get_where('member', $array);
		
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}
		else {
			return false;
		}
	}
	//end get name from id
	
	//get name and surname from id
	public function get_name_surname_string_from_id($id)
	{
		$name = "";
		$surname = "";
		
		$array = array('memid'=>$id);
		$query = $this->db->get_where('member', $array);
		
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row)
			{
				$name = $row->name;
				$surname = $row->surname;
			}
		}
		
		return $name ." " .$surname;
	}
	//end get name and surname from id
	
	//get reservation room detail
	public function get_reservation_detail($room, $date)
	{
		$array = array('roomname'=>$room, 'usedate'=>$date);
		$query = $this->db->get_where('reservation', $array);
		
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}
	}
	//end get reservation room detail
	
	//get roomtype from roomname
	public function get_roomtype_from_roomname($roomname)
	{
		$array = array('roomname' => $roomname);
		$query = $this->db->get_where('room', $array);
		
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row) {
				$roomtype = $row->roomtype;
			}
			return $roomtype;
		}
	}
	//end get roomtyp from roomname
	
}